package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.ProductItemVo;
import com.atguigu.spzx.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Mahone
 */
@Tag(name = "商品列表管理")
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Operation(summary = "分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSku>> findByPage(@PathVariable("page") Integer pageNum,
                                                   @PathVariable("limit") Integer pageSize,
                                                   ProductSkuDto productSkuDto){
        PageInfo<ProductSku> productSkuPageInfo = productService.findByPage(pageNum,pageSize,productSkuDto);
        return Result.ok(productSkuPageInfo);
    }

    @Operation(summary = "商品详情")
    @GetMapping("item/{skuId}")
    public Result<ProductItemVo> item(@PathVariable("skuId") Long skuId){
        ProductItemVo productItemVo = productService.selectItemInfo(skuId);
        return Result.ok(productItemVo);
    }

    @GetMapping("/getBySkuId/{skuId}")
    public Result<ProductSku> getBySkuId(@PathVariable Long skuId){
       ProductSku productSku = productService.getBySkuId(skuId);
        return Result.ok(productSku);
    }
}
